<template>
    <div>
        <div class="container">
            <!-- 头部 -->
            <div class="nav">
                <div class="nav_wrap">
                    <div class="quit" @click="$router.back()"></div>
                    <span>书架</span>
                    <div class="nav_icon">
                        <router-link tag="a" to="/shelf"></router-link>
                        <i v-show="!isTop" @click="topShow"></i>
                        <i class="topnav" v-show="isTop" @click="topShow"></i>
                    </div>
                </div>
            </div>
            <div class="wrap" v-show="isTop" @click.self="topShow">
                <div class="subnav">
                    <ul>
                        <router-link tag="li" to="/">
                            <img src="../assets/images/tp_1.png" alt="">
                            <span>首页</span>
                        </router-link>
                        <router-link tag="li" to="/library">
                            <img src="../assets/images/tp_02.png" alt="">
                            <span>书库</span>
                        </router-link>
                        <router-link tag="li" to="/shelf">
                            <img src="../assets/images/tp_03.png" alt="">
                            <span>书架</span>
                        </router-link>
                        <router-link tag="li" to="/user">
                            <img src="../assets/images/tp_04.png" alt="">
                            <span>账户</span>
                        </router-link>
                        <router-link tag="li" to="/pay">
                            <img src="../assets/images/tp_05.png" alt="">
                            <span>充值</span>
                        </router-link>
                        <router-link tag="li" to="/search">
                            <img src="../assets/images/tp_06.png" alt="">
                            <span>搜索</span>
                        </router-link>
                    </ul>
                </div>
            
            </div>
            <!-- 书架主体 -->
            <div class="main bor_bot">
                <div class="head">
                    <span>共有{{bookList.length}}本书</span>
                    <div class="btn">
                        <em v-show="!isShow" @click="isShow = true">管理</em>

                        <em v-show="isShow" @click="remove('all')">全部删除</em>
                        <em v-show="isShow" @click="remove">完成</em>
                    </div>
                </div>
                <ul v-if="bookList.length != 0">
                    <li v-for="(item,index) in bookList" :key="index">
                        <div class="img">
                            <img :src="item.iconUrl" alt="">
                        </div>
                        <div class="book_info">
                            <div class="book_tit">{{item.title}}</div>
                            <p>{{item.author}} | <span>{{ item.category }}</span></p>
                            <!-- <h4>最近更新 {{item.updata}}</h4> -->
                            <h4>最近阅读至 {{rank[index]}} 章</h4>
                            <h4>更新至{{ item.new }}</h4>
                        </div>
                        <div class="time">刚刚</div>
                        <div class="del" v-show="isShow" @click="del(index)"></div>
                    </li>
                </ul>
                <div class="emtry" v-else>
                    <div class="txt">
                        <span>书架空空如也，去书城里挑一本好书看吧</span>
                    </div>
                </div>
            </div>
            <!-- 搜索框 -->
            <router-link tag="div" to="/search" class="search">
                <div class="search_wrap">
                    <input type="text">
                    <button></button>
                </div>
            </router-link>
            <!-- 页脚信息 -->
            <div class="footer">
                <div class="foot_tit">
                    <ul>
                        <li>
                            <a href="javascript:;">首页</a>
                        </li>
                        <li>
                            <a href="javascript:;">书库</a>
                        </li>
                        <li>
                            <a href="javascript:;">书架</a>
                        </li>
                        <li>
                            <a href="javascript:;">账户</a>
                        </li>
                        <li>
                            <a href="javascript:;">客户端</a>
                        </li>
                    </ul>
                </div>
                <div class="foot_cont">
                    <div class="foot_info">
                        <p>客服QQ群：326738643</p>
                        <p>客服电话：010-86462015-800</p>
                        <p>©2020北京爱书客科技有限公司</p>
                        <p>京ICP备13037522号</p>
                    </div>
                    <div class="info_img">
                        <img src="../assets/images/ledu.png" alt="">
                        <span>乐读书城</span>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    export default {
        data(){
            return{
                bookList:[],//从本地存储获取收入书架的书单
                bookInds:null,//书架书本对应的下标（id）
                isShow:false,//控制按钮切换
                isTop: false,//判断子菜单的展示
                rank:[],//存储阅读历史
            }
        },
        created(){
            if (sessionStorage.getItem('bookArr') == null){
                return
            }
            this.bookList = sessionStorage.getItem('bookArr');
            this.bookList = JSON.parse(this.bookList);
            
            
            this.bookInds = sessionStorage.getItem('bookInd');
            this.bookInds = JSON.parse(this.bookInds);

            this.listAdd()
        },
        methods:{
            remove(str){//删除按钮
                if (str == 'all') {
                    console.log('全部删除');
                    this.bookList = [];
                    this.$toast.success('删除成功');
                    sessionStorage.removeItem('bookArr');
                    sessionStorage.removeItem('bookInd');
                } else {
                    console.log('完成编辑');
                }

                this.isShow = false;
            },
            del(ind){//单项删除
                this.bookList.splice(ind,1);//删除书籍信息
                sessionStorage.setItem('bookArr', JSON.stringify(this.bookList));

                this.bookInds.splice(ind,1);//删除对应的下标（id）
                sessionStorage.setItem('bookInd', JSON.stringify(this.bookInds));

                this.$toast({
                    message: '删除成功',
                    duration: 800
                })
            },
            topShow() {
                this.isTop = !this.isTop
            },
            listAdd(){
                this.bookList.forEach((item)=>{
                    let num = localStorage.getItem(item.title);
                    this.rank.push(num)
                    console.log(this.rank);
                })
            }
        }
    }
</script>

<style lang="scss" scoped>
.nav {
    background-color: #fff;

    .nav_wrap {
        padding: 0 14px;
        border-bottom: 1px solid #e0e0e0;
        display: flex;

        .quit {
            width: 10px;
            height: 45px;
            background-image: url('../assets/images/quit.png');
            background-repeat: no-repeat;
            background-size: 100%;
            background-position: center;
        }

        span {
            color: #333;
            font-size: 16px;
            display: block;
            text-align: center;
            line-height: 45px;
            width: 54%;
            padding-left: 70px;
        }

        .nav_icon {
            display: flex;
            align-items: center;
            justify-content: space-between;
            width: 80px;

            a {
                display: block;
                width: 25px;
                height: 22px;
                background-image: url('../assets/images/book_ico1.png');
                background-repeat: no-repeat;
                background-size: 100%;
                background-position: center;
            }

            i {
                display: block;
                width: 20px;
                height: 20px;
                background-image: url('../assets/images/bookMore_ico1.png');
                background-size: 100%;
                background-position: center;

            }

            .topnav {
                background-image: url('../assets/images/tp_close.png');
            }
        }
    }
}

.wrap {
    position: fixed;
    top: 45px;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: rgba(0, 0, 0, .8);
    z-index: 10;
    .subnav {
        width: 100%;
        background-color: #fff;
        padding-bottom: 18px;

        ul {
            display: flex;
            flex-wrap: wrap;

            li {
                width: 25%;
                text-align: center;
                padding-top: 20px;

                img {
                    width: 40px;
                    height: 40px;
                    margin: 0 auto 8px auto;
                }

                span {
                    font-size: 13px;
                    color: #666;
                }
            }
        }
    }

}

.main{
    
    .head{
        height: 41px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        border-bottom: 1px solid #eee;
        padding: 0 15px;
        span{
            display: block;
            width: 80px;
            height: 41px;
            line-height: 41px;
            font-size: 15px;
            color: #333;
        }
        .btn{
            display: flex;
            justify-content: space-between;
            em{
                display: block;
                padding: 0 12px;
                height: 26px;
                line-height: 26px;
                border: 1px solid #ea4136;
                font-size: 12px;
                text-align: center;
                color: #ea4136;
                border-radius: 4px;
                font-style: normal;
                &:last-of-type{
                    margin-left: 20px;
                }
            }
        }
    }
    ul{
        min-height: 282px;
        li{
            display: flex;
            padding: 24px 14px;
            border-bottom: 1px solid #eeeeee;
            position: relative;
            .img{
                padding-right: 12px;
                img{
                    width: 58px;
                    height: 82px;
                }
            }
            .book_info{
                flex: 1;
                .book_tit{
                    font-size: 17.5px;
                    color: #666;
                    line-height: 26px;
                    height: 26px;
                }
                p{
                    color: #999;
                    font-size: 12px;
                    line-height: 16px;
                    height: 16px;
                }
                h4{
                    color: #595959;
                    font-size: 12.5px;
                    line-height: 19px;
                    height: 19px;
                    overflow: hidden;
                }
            }
        }
    }
    .emtry{
        min-height: 282px;
        background-color: #f1f1f1;
        .txt{
            background-image: url('../assets/images/shujiaEmpty.png');
            background-repeat: no-repeat;
            background-position: center;
            background-size: 150px 130px;
            height: 187px;
            text-align: center;
            span{
                vertical-align: -167px;
                color: #999;
                font-size: 14px;
            }
        }
    }
    .time{
        width: 20%;
        text-align: center;
        color: #999;
        font-size: 12px;
        padding-top: 62px;
    }
    .del{
        width: 30px;
        height: 30px;
        background-image: url('../assets/images/del_icon.png');
        background-repeat: no-repeat;
        background-position: center;
        background-size: 20px;
        position: absolute;
        right: 10px;
        top: 18px;
    }
}

.bor_bot {
    border-bottom: 10px solid #eaeaea;
}

.search {
    padding: 10px 14px;

    .search_wrap {
        display: flex;
        padding: 4px 0 4px 17px;
        border: 1px solid #dbdbdb;
        height: 32px;
        border-radius: 20px;
        overflow: hidden;

        &>input {
            border: 0px;
            outline: none;
            flex: 6;
            color: #999;
        }

        &>button {
            flex: 1;
            background-image: url('../assets/images/searchBar.png');
            background-repeat: no-repeat;
            border: 0px;
            background-color: #fff;
            position: relative;
            border-left: 1px solid #dbdbdb;
            background-size: 18px;
            background-position: center;
        }
    }
}

.footer {
    padding: 16px 0px 32px 0px;
    background-color: #1c1a1a;

    .foot_tit {
        padding-bottom: 15px;

        ul {
            display: flex;

            li {
                flex: 1;

                a {
                    display: block;
                    font-size: 16px;
                    color: #b6b6b6;
                    text-align: center;
                    border-right: 1px solid #999999;

                }

                &:last-of-type {
                    a {
                        border: 0px;
                    }
                }
            }
        }
    }

    .foot_cont {
        display: flex;
        justify-content: space-between;
        padding: 0 16px;

        .foot_info {
            p {
                color: #b6b6b6;
                font-size: 12px;
                line-height: 28px;
            }
        }

        .info_img {
            img {
                width: 98px;
                height: 98px;
            }

            span {
                font-size: 12px;
                display: block;
                text-align: center;
                color: #b6b6b6;
                padding-top: 3px;
            }
        }
    }
}
</style>